package cn.sjx.graduate.service.impl;


import cn.sjx.graduate.domain.Employee;
import cn.sjx.graduate.redisenum.SetKeyInRedis;
import cn.sjx.graduate.service.IRedisService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Author: bo-feifei
 * @Date 2021/11/1 16:38
 * @Version 1.0
 */
@Service
public class RedisServiceImpl implements IRedisService {

    @Autowired
    private StringRedisTemplate template;

    @Override
    public Employee getUserByToken(String token) {
        String userJson = template.opsForValue().get(SetKeyInRedis.USERKEY.getName() + ":" + token);
        return JSON.parseObject(userJson, Employee.class);
    }

    @Override
    public void setUserByToken(String token, String value) {
        template.opsForValue().set(SetKeyInRedis.USERKEY.getName() + ":" + token,value,3,TimeUnit.HOURS);
    }
}
